﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RegisterationCommon.Common;
using System.Data;

namespace RegisterationCommon.School
{
    /// <summary>
    /// 学校信息实体类
    /// </summary>
    public class SchoolInfo
    {
        #region 局部变量
        //主键，自动编号
        private int _ID = 0;
        //学校名称
        private string _Name = "";
        //学校简介
        private string _Intro = "";
        //学校网址
        private string _Website = "";
        //学校地址
        private string _Address = "";
        //联系电话
        private string _Telphone = "";
        //招生指标
        private int _Count = 0;
        //A级学生登记时间说明
        private string _AInfo = "";
        //B级学生登记时间说明
        private string _BInfo = "";
        //C级学生登记时间说明
        private string _CInfo = "";
        //D级学生登记时间说明
        private string _DInfo = "";
        #endregion

        #region 属性列表
        /// <summary>
        /// D级学生登记时间说明
        /// </summary>
        public string DInfo
        {
            get { return _DInfo; }
            set { _DInfo = value; }
        }
        /// <summary>
        /// C级学生登记时间说明
        /// </summary>
        public string CInfo
        {
            get { return _CInfo; }
            set { _CInfo = value; }
        }
        /// <summary>
        /// B级学生登记时间说明
        /// </summary>
        public string BInfo
        {
            get { return _BInfo; }
            set { _BInfo = value; }
        }
        /// <summary>
        /// A级学生登记时间说明
        /// </summary>
        public string AInfo
        {
            get { return _AInfo; }
            set { _AInfo = value; }
        }
        /// <summary>
        /// 招生指标
        /// </summary>
        public int Count
        {
            get { return _Count; }
            set { _Count = value; }
        }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string Telphone
        {
            get { return _Telphone; }
            set { _Telphone = value; }
        }
        /// <summary>
        /// 学校地址
        /// </summary>
        public string Address
        {
            get { return _Address; }
            set { _Address = value; }
        }
        /// <summary>
        /// 学校网址
        /// </summary>
        public string Website
        {
            get { return _Website; }
            set { _Website = value; }
        }
        /// <summary>
        /// 学校简介
        /// </summary>
        public string Intro
        {
            get { return _Intro; }
            set { _Intro = value; }
        }
        /// <summary>
        /// 学校名称
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        /// <summary>
        /// 主键，自动编号
        /// </summary>
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        #endregion

        #region 方法列表

        #region 分页获取学校信息
        /// <summary>
        /// 分页获取学校信息
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>返回JSON格式的字符串</returns>
        public string GetSchoolInfoList(RParams RP)
        {
            //查询当前页
            DataTable dt = DBAction.ExecSP("sp_select_page", RP).Tables[0];
            //查询条件的总条数
            int totalCount = DBAction.GetDTFromSQL("select * from " + ETableName.SchoolInfo + " where " + RP.GetSqlParameter("Where").Value).Rows.Count;
            //返回Json
            return DBAction.DataTableToJson(dt, true, totalCount);
        }
        #endregion

        #region 不分页获取学校信息
        /// <summary>
        /// 不分页获取学校信息
        /// </summary>
        /// <returns>返回获取的DataTable</returns>
        public DataTable GetSchoolInfoList()
        {
            DataTable dt = DBAction.GetDTFromSQL("select * from " + ETableName.SchoolInfo + " ");
            return dt;
        }
        #endregion

        #region 根据学校编号查询学校信息
        /// <summary>
        /// 根据学校编号查询学校信息
        /// </summary>
        /// <param name="schID">学校编号</param>
        /// <returns>查询成功返回true,否则返回false</returns>
        public bool GetSchoolInfoByID(int schID)
        {
            DataTable dt = DBAction.GetDTFromSQL("Select * From " + ETableName.SchoolInfo + " where id=" + schID);
            if (dt.Rows.Count < 1)
            {
                return false;
            }
            this._ID = schID;
            this._Name = Convert.ToString(dt.Rows[0]["Name"]);
            this._Intro = Convert.ToString(dt.Rows[0]["Intro"]);
            this._Website = Convert.ToString(dt.Rows[0]["Website"]);
            this._Address = Convert.ToString(dt.Rows[0]["Address"]);
            this._Telphone = Convert.ToString(dt.Rows[0]["Telphone"]);
            this._Count = Convert.ToInt32(dt.Rows[0]["Count"]);
            this._AInfo = Convert.ToString(dt.Rows[0]["AInfo"]);
            this._BInfo = Convert.ToString(dt.Rows[0]["BInfo"]);
            this._CInfo = Convert.ToString(dt.Rows[0]["CInfo"]);
           // this._DInfo = Convert.ToString(dt.Rows[0]["DInfo"]);
            return true;
        }

        #endregion

        #region 添加学校信息
        /// <summary>
        /// 添加学校信息
        /// </summary>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddSchoolInfo()
        {
            RParams RP = new RParams();
            RP.Add("Name", this._Name, SqlDbType.VarChar);
            RP.Add("Intro", this._Intro, SqlDbType.VarChar);
            RP.Add("Website", this._Website, SqlDbType.VarChar);
            RP.Add("Address", this._Address, SqlDbType.VarChar);
            RP.Add("Telphone", this._Telphone, SqlDbType.VarChar);
            RP.Add("Count", this._Count, SqlDbType.Int);
            RP.Add("AInfo", this._AInfo, SqlDbType.VarChar);
            RP.Add("BInfo", this._BInfo, SqlDbType.VarChar);
            RP.Add("CInfo", this._CInfo, SqlDbType.VarChar);
            return AddSchoolInfo(RP);
        }
        /// <summary>
        /// 添加学校信息
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddSchoolInfo(RParams RP)
        {
            return DBAction.Insert(ETableName.SchoolInfo, RP);
        }
        #endregion

        #region 修改学校信息
        /// <summary>
        /// 修改学校信息
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool MdfSchoolInfo()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("Name", this._Name, SqlDbType.VarChar);
            RP.Add("Intro", this._Intro, SqlDbType.VarChar);
            RP.Add("Website", this._Website, SqlDbType.VarChar);
            RP.Add("Address", this._Address, SqlDbType.VarChar);
            RP.Add("Telphone", this._Telphone, SqlDbType.VarChar);
            RP.Add("Count", this._Count, SqlDbType.Int);
            RP.Add("AInfo", this._AInfo, SqlDbType.VarChar);
            RP.Add("BInfo", this._BInfo, SqlDbType.VarChar);
            RP.Add("CInfo", this._CInfo, SqlDbType.VarChar);
            string colFields = "Name,Intro,Website,Address,Telphone,Count,AInfo,BInfo,CInfo";
            string whereFields = "ID=@ID";
            return MdfSchoolInfo(colFields, whereFields, RP);
        }

        /// <summary>
        /// 修改学校信息
        /// </summary>
        /// <param name="colFields">修改的列</param>
        /// <param name="whereFields">修改条件</param>
        /// <param name="RP">数据集</param>
        ///  <returns>修改成功返回true,否则返回false</returns>
        public bool MdfSchoolInfo(string colFields, string whereFields, RParams RP)
        {
            return DBAction.Update(ETableName.SchoolInfo, colFields, whereFields, RP);
        }
        #endregion

        #region 修改学校招生数
        /// <summary>
        /// 修改学校招生数
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool MdfSchoolCount()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("Count", this._Count, SqlDbType.Int);
            RP.Add("AInfo", this._AInfo, SqlDbType.VarChar);
            RP.Add("BInfo", this._BInfo, SqlDbType.VarChar);
            RP.Add("CInfo", this._CInfo, SqlDbType.VarChar);
            string colFields = "Count,AInfo,BInfo,CInfo";
            string whereFields = "ID=@ID";
            return MdfSchoolCount(colFields, whereFields, RP);
        }

        /// <summary>
        /// 修改学校招生数
        /// </summary>
        /// <param name="colFields">修改的列</param>
        /// <param name="whereFields">修改条件</param>
        /// <param name="RP">数据集</param>
        ///  <returns>修改成功返回true,否则返回false</returns>
        public bool MdfSchoolCount(string colFields, string whereFields, RParams RP)
        {
            return DBAction.Update(ETableName.SchoolInfo, colFields, whereFields, RP);
        }
        #endregion

        #region 根据ID删除学校信息
        /// <summary>
        /// 根据ID删除学校信息
        /// </summary>
        /// <param name="schID">信息编号</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelSchoolInfo(int schID)
        {
            RParams RP = new RParams();
            RP.Add("ID", schID, SqlDbType.BigInt);
            string whereFields = "ID=@ID";
            return DBAction.Delete(ETableName.SchoolInfo, whereFields, RP);
        }
        /// <summary>
        /// 根据ID删除学校信息
        /// </summary>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelSchoolInfo()
        {
            return DelSchoolInfo(this._ID);
        }
        #endregion
        #endregion
    }
}
